/** 
 * Description:用户反馈DAO
 * Date:2012-6-10
 * Author:Along	
*/
package com.community.shopping.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.community.shopping.domain.UserComment;
import com.community.shopping.service.logic.Page;

public class UserCommentDao extends HibernateDaoSupport{
	private Log log = LogFactory.getLog(GoodsBrandDao.class);  
	

	public void save(UserComment userComment){
		getHibernateTemplate().saveOrUpdate(userComment);	
		log.debug("-------保存一行userComment-------");
	}

	public void delete(UserComment userComment){		  
		getHibernateTemplate().delete(userComment);
		log.debug("---------删除一行userComment-------");
	}


	public UserComment getUserCommentById(String id){
		UserComment comment=getHibernateTemplate().get(UserComment.class, Integer.parseInt(id));
		return comment;
	} 
	
	
	public List<?> getUserComment() {  		
	 return getHibernateTemplate().find(" from UserComment"); 
	 }

	public List<?> getUserComment(String sql){
		String finalsql="from UserComment where "+sql+" order by createTime desc";
		return getHibernateTemplate().find(finalsql);
	}  
	
	public List<?> getUserComment(String sql,Page page){
		String finalsql=" from UserComment where "+sql;
		Query   query   = this.getSession().createQuery(finalsql+" order by createTime desc"); 
		query.setFirstResult(page.getPageStartRow()>0?page.getPageStartRow()-1:0); 
		query.setMaxResults(page.getPageSize()); 
		if(page.getTotalRowsAmount()==0)
		{
		page.setTotalRowsAmount(getTotalCount(finalsql));
		}
		List   stu   =   query.list(); 
		return stu;
	} 
	
	public int getTotalCount(String sql)
	{
		Query   query   = this.getSession().createQuery("select count(*) "+sql); 
		int i=Integer.parseInt(query.list().get(0).toString());
		return i;
	}
	
	
	}
